<?php

/**
 * Class of Validate Receipt template
 *
 * @author BUI TIEN HIEP
 * @email bthiep@lhv.vn
 */
class ValidateReceipt extends AbstractValidateFactory implements ICreatePolicyFactory  {

    public function __construct($policy) {
        $this->policy = $policy;
    }

    /**
     * Create receipt policy
     * @return ISpecification
     */
    private function createPolicyFactory() {
        $field = $this->policy['rules'][0]['field'];
        $value = $this->policy['rules'][0]['value'];
        return $this->isGreaterThan($field, $value)->and_(!$this->isEqual('receipt_id', NULL));
    }

    /**
     * Validate receipt policy
     * @param type $expenses
     * @return boolean
     */
    public function validate($expenses = array()) {
        $bRet = false;
        if ($this->createPolicyFactory()->isSatistifiedBy($expenses)) {
            $bRet = true;
            $this->message = $this->policy['message'];
        }
        return $bRet;
    }

}
